<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Users.aspx.cs" Inherits="Users" %>

<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {

        // If user is not authenticated, redirect to Login page
        if (!Request.IsAuthenticated)
        {
            FormsAuthentication.RedirectToLoginPage();
            Response.End();
        }
        // Create Roles
        if (!Roles.RoleExists("marketolog")) Roles.CreateRole("marketolog");
        if (!Roles.RoleExists("admin")) Roles.CreateRole("admin");
        if (!Roles.RoleExists("logist")) Roles.CreateRole("logist");
        if (!Roles.RoleExists("finansist")) Roles.CreateRole("finansist");

        // Add current user to both roles
        //if (!Roles.IsUserInRole(&#8220;Managers&#8221;))
        //Roles.AddUserToRole(User.Identity.Name, &#8220;Managers&#8221;);
        //if (!Roles.IsUserInRole(&#8220;Sales&#8221;))
        //Roles.AddUserToRole(User.Identity.Name, &#8220;Sales&#8221;);
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="pagetitle">&#1055;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1077;&#1083;&#1080;</div>
    <div class="contact">
        <div class="clear">
            <%--<asp:GridView id="grdUsers" DataSourceID="srcUsers" Runat="server" 
                BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
                CellPadding="3" GridLines="Horizontal" Width="600px" >
                <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                <AlternatingRowStyle BackColor="#F7F7F7" />
            </asp:GridView>
            <asp:ObjectDataSource id="srcUsers" TypeName="System.Web.Security.Membership" SelectMethod="GetAllUsers"
            Runat="server" />--%>
            <%--<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
                DataObjectTypeName="System.Web.Security.MembershipUser" 
                SelectMethod="GetAllUsers" TypeName="System.Web.Security.Membership">
            </asp:ObjectDataSource>
            <asp:GridView id="grdUsers" DataSourceID="ObjectDataSource1" Runat="server" 
                BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
                CellPadding="3" GridLines="Horizontal" Width="600px" >
                <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                <AlternatingRowStyle BackCol
                or="#F7F7F7" />
            </asp:GridView>--%>
            <div class="usersTable">
            <asp:LinqDataSource ID="UsersDataSource" 
                ContextTypeName="UsersDBClassesDataContext" runat="server"     
                TableName="UsersLists" 
                Select="new (UserName, Email, RoleName, CreateDate, LastLoginDate, PropertyValuesString)"  />
      
            <asp:GridView id="grdUsers" DataSourceID="UsersDataSource" Runat="server" 
                AutoGenerateColumns="False"   AutoGenerateEditButton="false" AutoGenerateDeleteButton="false"
                AllowPaging="True" PageSize="8" CssClass="usersTable" >
                <Columns>
                    <asp:BoundField DataField="UserName" HeaderText="UserName" 
                        SortExpression="UserName" ReadOnly="True" />
                    <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" 
                        ReadOnly="True" />
                    <asp:BoundField DataField="RoleName" HeaderText="RoleName" 
                        SortExpression="RoleName" ReadOnly="True" />
                    <asp:BoundField DataField="CreateDate" HeaderText="CreateDate" 
                        SortExpression="CreateDate" ReadOnly="True" />
                    <asp:BoundField DataField="LastLoginDate" HeaderText="LastLoginDate" 
                        SortExpression="LastLoginDate" ReadOnly="True" />
                    <asp:BoundField DataField="PropertyValuesString" 
                        HeaderText="PropertyValuesString" SortExpression="PropertyValuesString" 
                        ReadOnly="True" />
                                                            
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:LinkButton ID="DeleteButton1" runat="server" CausesValidation="False"   PostBackUrl="~/EditUser.aspx"
                                Text="Edit" />
                        </ItemTemplate>
                    </asp:TemplateField>
                                                            
                </Columns>
                <EmptyDataTemplate>
                    &#1048;&#1084;&#1103; &#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1077;&#1083;&#1103;
                </EmptyDataTemplate>
            </asp:GridView>
            </div>
        </div>
    </div>
</asp:Content>
